(function() {
    angular.module('webApp').controller("FenxiaogradeCtrl", FenxiaogradeCtrl);
    FenxiaogradeCtrl.$inject = ['$scope', 'dataService', '$location', '$state', 'helper']

    function FenxiaogradeCtrl($scope, dataService, $location, $state, helper) {
        $scope.listAction = function() {
            console.error("0000000000")

            $scope.page_Size = 10;
            $scope.getFenxiaogradeList(1);

        }
        $scope.getFenxiaogradeList = function(page_No) {
            var query = { page_no: page_No, page_size: $scope.page_Size };
            console.error("111111111")
            dataService.fenxiaogradeGet(query).then(function(result) {
                if (result.Msg) {
                    helper.myAlert("error:" + result.Msg);
                } else {
                    $scope.fenxiaogrades = result.shop;
                    $scope.fenxiaogradesTotal = result.total_count;
                    // helper.myAlert("success",null,null,function(){
                    // 	$state.go("fenxiaograde.list");
                    // });
                }
            });
        }
        $scope.addAction = function() {
            var grade_id = $location.search().grade_id;
            if (grade_id) {
                dataService.fenxiaogradeOne(grade_id).then(function(fenxiaograde) {
                    $scope.fenxiaograde = fenxiaograde;
                    console.log($scope.fenxiaograde);
                });
            } else {
                $scope.fenxiaograde = {};
                $scope.fenxiaograde.count = 0;
                $scope.fenxiaograde.amount = 0;
            }
        }
        $scope.FenxiaogradeDelete = function(grade_id) {
            dataService.fenxiaogradeDelete(grade_id).then(function(r) {
                if (r.Msg) {
                    helper.myAlert("error:" + r.Msg);
                } else {
                    helper.myAlert("success", null, null, function() {
                        $scope.listAction();
                    });
                }
            });
        }
        $scope.FenxiaogradeInfo = function() {
            var grade_id = $location.search().grade_id;
            if (grade_id) {
                dataService.fenxiaogradeOne().then(function(fenxiaograde) {
                    $scope.fenxiaograde = fenxiaograde;
                });
            }
        }
        $scope.FenxiaogradeAdd = function() {
            if ($scope.fenxiaograde.grade_id) {
                dataService.fenxiaogradeUpdate($scope.fenxiaograde).then(function(r) {
                    if (r.Msg) {
                        helper.myAlert("error:" + r.Msg);
                    } else {
                        helper.myAlert("success", null, null, function() {
                            $state.go("fenxiaograde.list");
                        });
                    }
                });
            } else {
                dataService.fenxiaogradeAdd($scope.fenxiaograde).then(function(r) {
                    if (r.Msg) {
                        helper.myAlert("error:" + r.Msg);
                    } else {
                        helper.myAlert("success", null, null, function() {
                            $state.go("fenxiaograde.list");
                        });
                    }
                });
            }

        }
    }
})();